package chapters21;

import java.lang.reflect.*;

/**
 * Created by xinxuchu on 2020/2/23.
 */
public class Demo1 {


    public static void main(String[] args) throws Exception {
        try {
            Class classtype = Class.forName("chapters21.test");
            System.out.println(classtype.getName());
            System.out.println(classtype.getSimpleName());
            System.out.println("*****************************");

            //class获取类字段练习
            Field[] field = classtype.getDeclaredFields();
            for (Field field1:field){
                System.out.println(field1.getName()+"--"+ Modifier.isPublic(field1.getModifiers()));
            }
            System.out.println("*****************************");
            //class的到方法练习
            Method[] methods = classtype.getMethods();

            //获取所有public的方法
            for (Method method : methods){
                System.out.println(method.getName());
            }
            System.out.println(methods.length);

            //获取本类新增的方法,这里非public也会获取
            Method[] methodsNew = classtype.getDeclaredMethods();
            for (Method method : methodsNew){
                System.out.println(method.getName());
            }
            System.out.println(methodsNew.length);


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
